package com.aneliya.framework.mvc;

import com.aneliya.framework.mvc.controller.Controller;
import com.aneliya.framework.mvc.controller.IController;
import com.aneliya.framework.mvc.controller.MVCEvent;
import com.aneliya.framework.mvc.model.IModel;
import com.aneliya.framework.mvc.model.Model;
import com.aneliya.framework.mvc.model.Proxy;
import com.aneliya.framework.mvc.view.IView;
import com.aneliya.framework.mvc.view.Mediator;
import com.aneliya.framework.mvc.view.View;

public class Facade implements IController, IModel, IView {

	private static Facade instance;
	public static Facade getInstance() {
		if (instance == null) {
			instance = new Facade();
		}
		return instance;
	}

	private Controller controller;
	private View view;
	private Model model;
	
	protected Facade() {
		initializeController();
		initializeView();
		initializeModel();
	}
	
	protected void initializeController() {
		controller = Controller.getInstance();
	}

	protected void initializeView() {
		view = View.getInstance();
	}

	protected void initializeModel() {
		model = Model.getInstance();
	}

	public void dispatchMVCEvent(MVCEvent event) throws InstantiationException,
			IllegalAccessException {
		controller.dispatchMVCEvent(event);
	}

	
	public void registerCommand(String eventType, Class<?> commandClass)
			throws Exception {
		controller.registerCommand(eventType, commandClass);
	}

	
	public void removeCommand(String eventType) throws Exception {
		controller.removeCommand(eventType);
	}

	
	public void registerProxy(Proxy proxy, String name) throws Exception {
		model.registerProxy(proxy, name);
	}

	
	public void removeProxy(String name) throws Exception {
		model.removeProxy(name);
	}

	
	public Proxy retrieveProxy(String name) throws Exception {
		return model.retrieveProxy(name);
	}

	
	public void registerMediator(Mediator mediator, String name)
			throws Exception {
		view.registerMediator(mediator, name);
	}

	
	public void removeMediator(String name) throws Exception {
		view.removeMediator(name);
	}

	
	public Mediator retrieveMediator(String name) throws Exception {
		return view.retrieveMediator(name);
	}

}
